package com.bins.music.player.ui;

import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.stage.Modality;
import javafx.stage.Stage;

public class AlertStage extends Stage {

    private final Label headerTextLabel;

    private final Label contentTextLabel;

    private ButtonType buttonType;

    public AlertStage(Stage primaryStage) {

        buttonType = ButtonType.CANCEL;

        this.initOwner(primaryStage);

        this.initModality(Modality.WINDOW_MODAL);

        this.setTitle("删除音乐文件");

        VBox vBox = new VBox(10);

        headerTextLabel = new Label();

        contentTextLabel = new Label();

        Button okButton = getOkButton();

        HBox hbox2 = new HBox(5);

        hbox2.setAlignment(Pos.CENTER_RIGHT);

        vBox.getChildren().addAll(headerTextLabel, contentTextLabel, okButton);

        vBox.setPadding(new Insets(10, 5, 5, 5));

        vBox.setAlignment(Pos.TOP_CENTER);

        BorderPane jfxDecorator = new BorderPane();

        ObservableList<Image> icons = primaryStage.getIcons();

        if (!icons.isEmpty()) {
            Image image = icons.get(0);
            this.getIcons().add(image);
            ImageView imageView = new ImageView(image);
            imageView.setFitWidth(16.0);
            imageView.setPreserveRatio(true);
            // jfxDecorator.setGraphic(imageView);
        }
        Scene scene = new Scene(jfxDecorator,340, 148);

        scene.getStylesheets().addAll((getClass().getResource("/css/main.css").toExternalForm()), (getClass().getResource("/css/jfoenix-components.css").toExternalForm()));

        this.setScene(scene);

        this.setOnCloseRequest(event -> {
            buttonType = ButtonType.CANCEL;
            this.hide();
        });

        this.setResizable(false);
    }

    private Button getOkButton() {
        Button okButton = new Button();
        okButton.setText("确定");

        Color color1 = Color.BLACK;

        Border border = new Border(new BorderStroke(
                color1, color1, color1, color1,
                BorderStrokeStyle.SOLID,
                BorderStrokeStyle.SOLID,
                BorderStrokeStyle.SOLID,
                BorderStrokeStyle.SOLID,
                new CornerRadii(5),
                new BorderWidths(1),
                new Insets(1, 1, 1, 1)
        ));

        okButton.setBorder(border);

        okButton.setOnAction(event -> {
            buttonType = ButtonType.OK;
            this.hide();
        });
        return okButton;
    }

    public void setHeaderText(String text) {
        headerTextLabel.setText(text);
    }

    public void setContentText(String text) {
        contentTextLabel.setText(text);
    }

    public ButtonType showWaitResult() {
        super.showAndWait();
        return buttonType;
    }
}